package com.polaris.live.im.sfs.processor.impl

import com.polaris.live.common.manager.CoroutineScopeManager
import com.polaris.live.common.util.JsonUtils
import com.polaris.live.im.manager.ImNoticeManager
import com.polaris.live.im.sfs.GAME_NOTICE_PARTY_GAMESETTLEMENT
import com.polaris.live.im.sfs.bean.pusher.PusherNoticeMessage
import com.polaris.live.im.sfs.core.bean.DataArgument
import com.polaris.live.im.sfs.processor.AbstractMessageProcessor
import com.polaris.live.resp.back_resp.PartyGameSettlementResp
import kotlinx.coroutines.withContext

/**
 * GameResultMessageProcessor 游戏结算通知
 *
 * @author Created by 半仙 on 2024/3/13/013 10:57
 */
class GameResultMessageProcessor : AbstractMessageProcessor() {

    override fun shouldProcess(type: Int, command: String): Boolean {
        return command == GAME_NOTICE_PARTY_GAMESETTLEMENT
    }

    override suspend fun handle(type: Int, command: String, argument: DataArgument) {
        val data = argument.getData<PusherNoticeMessage>() ?: return
        val message =
            JsonUtils.fromJson<List<PartyGameSettlementResp>>(data.content) ?: return
        withContext(CoroutineScopeManager.mainDispatcher) {
            ImNoticeManager.onReceivGameResultMessage(message)
        }
    }
}